(function () {
    var defaultTime=moment(new Date).format('YYYY-MM-DD');
    jQuery('#paidDate').val(defaultTime);
    jQuery('#paymentDate').val(defaultTime);
    var contractId=jQuery('#contractId').val();
    var contractType=jQuery('#contractType').val();
    var contractSum=jQuery('#paySum1').val();//合同总额
    var paySum;//剩余回款总额
    var remain;//剩余开票金额
    var oldpay;
    var oldpayment;
    var oldnBeLeftOverPrice;
    var oldReceivednBeLeftOverPrice;
    var sumScheduleSum=jQuery('#sumScheduleSum').val();
    /*if(jQuery('#superior').val()!="成套处"){
    	jQuery('#accHandler').css("display","none");
    	jQuery('#accHandlerDate').css("display","none");
    	jQuery('#handlerText').css("display","none");
    	jQuery('#handlerContent').css("display","none");
    }*/
    if(jQuery('#divideScales').val()=="0"){
    	jQuery('#tab1').css("display","none");
    }
    //jQuery("#payMan").select2().trigger("change");
    jQuery("#paymentMan").select2().trigger("change");
    jQuery("#sReceivedPaymentPersonId").select2().trigger("change");
//获取回款计划tabs页面数据 服务器分页
    var serverData = {};
    var	serverTable;
    jQuery(document).ready(function () {
        serverTable = jQuery('#scheduleTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url": window.rootPath + '/ui/paySchedule/'+contractId+'/'+contractType+'/getData',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [
                  {
                      data: null
                  },
                  {
                      data: 'sAccountsReceivableTypeId.sAccountsReceivableTypeName'
                  },
                  {
                      data: 'nTotalPrice'
                  },
                  {
                      data:'dAccountsReceivablePlanDate',
                      render: function (data, type, full, meta) {
                          if (data)
                              return moment(data).format('YYYY/MM/DD');
                          else
                              return '';
                      }
                  },
                  {
                      data:'sMemo',
  	                render:function(data,type,full,meta){
  	                	if(data == null || data == undefined || data == ""){
  							return data;
  						}else{
  							return (data.length > 40) ? '<font title="'+data+'">'+data.substring(0,40)+'...'+'</font>' : data;
  						}
  					}
                  }
              ],
              "drawCallback": function (oSettings) {
                  var k = 0;
                  var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                  for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                      $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                      k++;
                  }
              }
        });
        
        var serverData5 = {};
        var	serverTable5;
        serverTable5 = jQuery('#resultScaleTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url": window.rootPath + '/ui/contract/getDivideScale',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: 'functionary'
                },
                {
                	data: 'belongArea'
                },
                {
                    data: 'scaleDivide'
                },
                {
                    data: 'percent'
                },
                {
                    data: 'memo'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
    
    
    var InvoiceTotalDate = {};
    var	InvoiceTotalTable;
    var oldtable = "";
    function InvoiceTotalTablelength(key,table){
    	var oldkey = InvoiceTotalDate.key == undefined ? "" : InvoiceTotalDate.key;
    	InvoiceTotalDate.key = key;
    	InvoiceTotalTable = jQuery('#' + table).DataTable({
    		"serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/invoice/getpage1',
                "data": function (d) {
                    return $.extend({}, d, InvoiceTotalDate);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: null,
                    defaultContent: "",
                    render: function (data, type, full, meta) {
                        var id=data.contractId
                        var operate ='<input type="radio" name="radio1" class="checkchild">';
                        return operate;
                    }
                },
                {
                    data: 'sInvoiceIdentifyType',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'sInvoiceName',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 15) ? '<font title="'+data+'">'+data.substring(0,15)+'...'+'</font>' : data;
						}
					}
                },
                {
                	data: 'nInvoiceActualPrice'
                },
                {
                	data: 'nBeLeftOverPrice'
                },
                {
                	data: 'sInvoicePeopleName'
                },
                {
                    data: 'sInvoiceAccount',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 15) ? '<font title="'+data+'">'+data.substring(0,15)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'sInvoiceCustomerName'
                },
                {
                    data: 'sInvoiceCustomerAccount'
                },
                {
                	data: 'sInvoiceTradeType'
                },
                {
                    data: 'dInvoiceDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY-MM-DD');
                        else
                            return '';
                    }
                },
                {
                	data: 'sInvoiceMemo'
                },
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    	if(oldkey != key){
    		InvoiceTotalDate.key=key;
    		InvoiceTotalTable.draw();
    	}else{
    		if(oldtable != table){
    			InvoiceTotalDate.key=key;
        		InvoiceTotalTable.draw();
    		}else{
    			InvoiceTotalTable.draw();
    		}
    	}
    	oldtabletable = table;
    }
    
    //});
    jQuery('#clearsInvoiceTotalId').on( 'click', function() {
    	jQuery('#sInvoiceTotalId').val("");
    	jQuery('#sInvoiceTotalname').val("");
    });
    jQuery('#getsInvoiceTotalId').on( 'click', function() {
    	jQuery('#search1').val("");
    	InvoiceTotalTablelength(jQuery('#search1').val(),'invoiceTotalTable');
		jQuery("#InvoiceTotalIdModel").modal('show');
	});
    
    jQuery('#btn-search1').on( 'click', function() {
    	InvoiceTotalTablelength(jQuery('#search1').val(),'invoiceTotalTable');
	});
    
    jQuery('#btn-reset1').on( 'click', function() {
    	jQuery('#search1').val("");
    	InvoiceTotalTablelength(jQuery('#search1').val(),'invoiceTotalTable');
	});
    
    jQuery('.getLaction').on('click', function(){
    	var selects=getSelectR("#invoiceTotalTable",1);
		if(selects.length>1){
   		   message("只能引入一条开票信息！");
   	    }
   	    else if(selects.length==0){
   		    message("没有选中开票信息！");
   	    }else if(selects.length==1){
   	    	jQuery("#sInvoiceTotalId").val(selects[0].id);
   	    	jQuery("#sInvoiceTotalname").val(selects[0].sInvoiceName);
		   	jQuery("#paymentSum").val(selects[0].nBeLeftOverPrice);
		   	oldnBeLeftOverPrice = selects[0].nBeLeftOverPrice;
		   	jQuery("#paymentDate").val(selects[0].dInvoiceDate.substring(0,10));
		   	jQuery("#paymentMan").val(selects[0].sInvoicePeopleId);
		   	jQuery("#paymentMan").select2().trigger("change");
   	    	jQuery("#InvoiceTotalIdModel").modal('hide');
   	    }
    });
    
    function getSelectR(tableId,num){
 	   var selects=[];
 	   var selecttr=tableId+" tbody tr"
 	   jQuery(selecttr).each(function(){
 			var isChecked = $(this).children("td").eq(num).find("input:radio").prop("checked");
 			if(isChecked)
 			{  
 				var data = $(tableId).dataTable().fnGetData($(this));
 				selects.push(data);
 			}
 		})
 		return selects
    }
    
    
    
    /*-----------------------------------选择凭据------------------------------------------*/
    
    jQuery('#clearsReceivedPaymentTotalId1').on(
    		'click',
    		function() {
    			jQuery('#sReceivedPaymentTotalId1').val("");
    			jQuery('#sReceivedPaymentTotalId-identify1').val("");
    		});
    jQuery('#getsReceivedPaymentTotalId1').on(
			'click',
			function() {
				jQuery('#searchReceived1').val("");
				ReceivedPaymentTotalTablelength("","ReceivedPaymentTotalTable1");
				jQuery("#ReceivedPaymentTotalModel1").modal('show');
			});
    
    jQuery('#btn-search-rec1').on( 'click', function() {
    	ReceivedPaymentTotalTablelength(jQuery('#searchReceived1').val(),"ReceivedPaymentTotalTable1");
	});
    
    jQuery('#btn-reset-rec1').on( 'click', function() {
    	jQuery('#searchReceived1').val("");
    	ReceivedPaymentTotalTablelength(jQuery('#searchReceived1').val(),"ReceivedPaymentTotalTable1");
	});
  //确认选择
    jQuery('.getReceived2').on('click', function(){
    	var selects=getSelectR("#ReceivedPaymentTotalTable1",1);
		if(selects.length>1){
   		   message("只能引入一条回款凭据！");
   	    }
   	    else if(selects.length==0){
   		    message("没有选中回款凭据！");
   	    }else if(selects.length==1){
   	    	jQuery("#sReceivedPaymentTotalId1").val(selects[0].id);
   	    	if(selects[0].id != "" && selects[0].id != undefined ){
   	    		jQuery("#sReceivedPaymentTotalId-identify1").val(selects[0].sReceivedPaymentsIdentifyNumber);
   	    	}
		   	jQuery("#nReceivedPaymentActualPrice1").val(selects[0].nBeLeftOverPrice);
		   	oldReceivednBeLeftOverPrice = selects[0].nBeLeftOverPrice;
		   	jQuery("#dReceivedPaymentPlanAccDate1").val(moment(selects[0].dReceivedPaymentsDate).format('YYYY-MM-DD'));
		   	jQuery("#dReceivedPaymentActualAccDate1").val(moment(selects[0].dReceivedPaymentsDate).format('YYYY-MM-DD'));
		   	jQuery("#sReceivedPaymentMemo1").val(selects[0].sReceivedPaymentMemo);
		   	jQuery("#sReceivedPaymentPersonId1").val(selects[0].sReceivedPaymentPersonId);
		   	jQuery("#sReceivedPaymentPersonId1").select2().trigger("change");
   	    	jQuery("#ReceivedPaymentTotalModel1").modal('hide');
   	    }
    });
    
    var ReceivedPaymentTotalTable;
    var ReceivedPaymentTotalR={};
    var oldReceivedtable;
    function ReceivedPaymentTotalTablelength(key,table){
    	var oldkey = ReceivedPaymentTotalR.key == undefined ? "" : ReceivedPaymentTotalR.key;
    	ReceivedPaymentTotalR.key=key;
    	ReceivedPaymentTotalTable = jQuery('#' + table).DataTable({
    		"serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/ReceivedPaymentTotalInfo/getPage1',
                "data": function (d) {
                    return $.extend({}, d, ReceivedPaymentTotalR);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: null,
                    defaultContent: "",
                    render: function (data, type, full, meta) {
                        var id=data.contractId
                        var operate ='<input type="radio" name="radio1" class="checkchild">';
                        return operate;
                    }
                },
                {
                    data: 'sReceivedPaymentsIdentifyType.title',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'sReceivedPaymentsIdentifyNumber',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 15) ? '<font title="'+data+'">'+data.substring(0,15)+'...'+'</font>' : data;
						}
					}
                },
                {
                	data: 'sReceivedPaymentsCustomerName',
                	render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 15) ? '<font title="'+data+'">'+data.substring(0,15)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'sReceivedPaymentsName',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 15) ? '<font title="'+data+'">'+data.substring(0,15)+'...'+'</font>' : data;
						}
					}
                },
                {
                	data : 'dReceivedPaymentsDate',
					render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data: 'sReceivedPaymentTradeType'
                },
                {
                	data: 'nReceivedPaymentActualPrice'
                },
                {
                	data: 'nBeLeftOverPrice'
                },
                {
                	data: 'sReceivedPaymentPersonIdName'
                },
                {
                	data : 'sReceivedPaymentMemo',
					 render:function(data,type,full,meta){
	   					 return '<font title="'+data+'">'+stringCut(data, 10)+'</font>';
	   	             }
                },
                {
                	data: 'sReceivedPaymentTradeWay'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    	if(oldkey != key){
    		ReceivedPaymentTotalR.key=key;
    		ReceivedPaymentTotalTable.draw();
    	}else{
    		if(oldReceivedtable != table){
    			ReceivedPaymentTotalR.key=key;
        		ReceivedPaymentTotalTable.draw();
    		}else{
    			ReceivedPaymentTotalTable.draw();
    		}
    	}
    	oldReceivedtable = table;
    }
    

    jQuery('#clearsReceivedPaymentTotalId').on(
    		'click',
    		function() {
    			jQuery('#sReceivedPaymentTotalId').val("");
    			jQuery('#sReceivedPaymentTotalId-identify').val("");
    		});
    
    jQuery('#getsReceivedPaymentTotalId').on(
			'click',
			function() {
				jQuery('#searchReceived').val("");
				ReceivedPaymentTotalTablelength("","ReceivedPaymentTotalTable");
				jQuery("#ReceivedPaymentTotalModel").modal('show');
			});
    
    jQuery('#btn-search-rec').on('click', function() {
    	ReceivedPaymentTotalTablelength(jQuery('#searchReceived').val(),"ReceivedPaymentTotalTable");
	});
    
    jQuery('#btn-reset-rec').on('click', function() {
    	jQuery('#searchReceived').val("");
    	ReceivedPaymentTotalTablelength(jQuery('#searchReceived').val(),"ReceivedPaymentTotalTable");
	});
  //确认选择
    jQuery('.getReceived1').on('click', function(){
    	var selects=getSelectR("#ReceivedPaymentTotalTable",1);
		if(selects.length>1){
   		   message("只能引入一条回款凭据！");
   	    }
   	    else if(selects.length==0){
   		    message("没有选中回款凭据！");
   	    }else if(selects.length==1){
   	    	jQuery("#sReceivedPaymentTotalId").val(selects[0].id);
   	    	jQuery("#sReceivedPaymentTotalId-identify").val(selects[0].sReceivedPaymentsIdentifyNumber);
		   	jQuery("#nReceivedPaymentActualPrice").val(selects[0].nBeLeftOverPrice);
		   	oldReceivednBeLeftOverPrice = selects[0].nBeLeftOverPrice;
		   	jQuery("#dReceivedPaymentPlanAccDate").val(moment(selects[0].dReceivedPaymentsDate).format('YYYY-MM-DD'));
		   	jQuery("#dReceivedPaymentActualAccDate").val(moment(selects[0].dReceivedPaymentsDate).format('YYYY-MM-DD'));
		   	jQuery("#sReceivedPaymentMemo").val(selects[0].sReceivedPaymentMemo);
		   	jQuery("#sReceivedPaymentPersonId").val(selects[0].sReceivedPaymentPersonId);
		   	jQuery("#sReceivedPaymentPersonId").select2().trigger("change");
   	    	jQuery("#ReceivedPaymentTotalModel").modal('hide');
   	    }
    });
//-----------   
//获取回款历史tabs页面数据 服务器分页
    var serverData1 = {};
    var	serverTable1;
    jQuery(document).ready(function () {
		serverTable1 = jQuery('#payTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url": window.rootPath + '/ui/payment/payHistory/'+contractId+'/'+contractType+'/getData',
                "data": function (d) {
                    return $.extend({}, d, serverData1);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: null,
                    defaultContent: "",
                    render: function (data, type, full, meta) {
                        var operate = '<input type="checkbox" class="checkchild">';
                        return operate;

                    }
                },
                {
                    data: 'nReceivedPaymentDetailPrice'
                },
                {
                    data: 'sReceivedPaymentTradeWay.title'
                },
                {
                    data:'dReceivedPaymentPlanAccDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY-MM-DD');
                        else
                            return '';
                    }
                },
                {
                    data:'sReceivedPaymentPersonName'
                },
                {
                	data:'sCreateUserName'
                },
                {
                    data:'dReceivedPaymentActualAccDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY-MM-DD');
                        else
                            return '';
                    }
                },
                {
                    data:'sReceivedPaymentMemo'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
    //编辑金额
    jQuery('.changeBtn').on('click', function () {
            jQuery('#changeEditModal').modal('show');
    });
    jQuery('.qdBtn').on('click', function () {
    	var money = jQuery('#money1').val();
    	var bfb = jQuery('#bfb').val();
    	var s = parseFloat(money)*parseFloat(bfb)/100;
        jQuery('#paidSum').val(s);
        jQuery('#changeEditModal').modal('hide');
        
    });
    //编辑回款历史
    jQuery('.editPayBtn').on('click', function () {
        var selects=getSelect("#payTable",1);
        if(selects.length>1){
            $.springLemonDialog({
                content: '只能编辑一条记录',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
        }
        else if(selects.length==0){
            $.springLemonDialog({
                content: '请选择要编辑的记录',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
        }else if(selects.length==1) {
            jQuery('#id').val(selects[0].id);
            jQuery('#sReceivedPaymentTotalId1').val(selects[0].sReceivedPaymentTotalId);
            if(selects[0].sReceivedPaymentTotalId != "" && selects[0].sReceivedPaymentTotalId != undefined ){
            	jQuery('#sReceivedPaymentTotalId-identify1').val(selects[0].sReceivedPaymentTotalId.sReceivedPaymentsIdentifyNumber);
   	    	}
            jQuery('#nReceivedPaymentActualPrice1').val(selects[0].nReceivedPaymentDetailPrice);
            oldpay=jQuery('#nReceivedPaymentActualPrice1').val();
            jQuery('#sReceivedPaymentPersonId1').val(selects[0].sReceivedPaymentPersonId);
            jQuery("#sReceivedPaymentPersonId1").select2().trigger("change");
            if (selects[0].dReceivedPaymentPlanAccDate) {
                var time = moment(selects[0].dReceivedPaymentPlanAccDate).format('YYYY-MM-DD');
                jQuery('#dReceivedPaymentPlanAccDate1').val(time);
            }
            if (selects[0].dReceivedPaymentActualAccDate) {
                var time = moment(selects[0].dReceivedPaymentActualAccDate).format('YYYY-MM-DD');
                jQuery('#dReceivedPaymentActualAccDate1').val(time);
            }
        	jQuery('#sCreateUserId-text1').val(selects[0].sCreateUserName);
        	if(selects[0].sReceivedPaymentTradeWay){
        		jQuery('#sReceivedPaymentTradeWay1').val(selects[0].sReceivedPaymentTradeWay.id);
        		jQuery("#sReceivedPaymentTradeWay1").select2().trigger("change");
        	}
            jQuery('#sReceivedPaymentMemo1').val(selects[0].sReceivedPaymentMemo);
            paySum=jQuery('#paidRemain').val();//剩余回款总额
            jQuery('#registPayEditModal').modal('show');
        }
    });
    ///新增保存回款
    jQuery('.savePayBtn').on('click', function () {
        if(jQuery("#paidForm")&&!jQuery("#paidForm").Validform({
                tiptype :3,
                showAllError :true
            }).check(false)){
            return;
        };
        var paid=jQuery('#paySum').val();
        var remainSum=sumScheduleSum-paid;
        paySum=jQuery('#paidRemain').val();//剩余回款总额
        var paidSum = jQuery('#nReceivedPaymentActualPrice').val();
        if(parseFloat(oldReceivednBeLeftOverPrice) < parseFloat(paidSum)){
        	$.springLemonDialog({
                content: '输入金额大于开票剩余金额，请重新输入！',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
            return;
        }
       // if(parseInt(paidSum,10)<=parseInt(paySum,10)){
            if(parseInt(paidSum,10)<=parseInt(remainSum,10)) {
                savepay(paidSum);
            }
            else{
                $.springLemonDialog({
                    content: '回款总额大于计划总额，请减少回款金额！',// 确认文本
                    clickButton: function (sender, modal, index) {// 按钮事件处理
                        $(this).closeDialog(modal);
                    }
                });
                return;
            }
        //}
        //else{
        //    $.springLemonDialog({
        //        content: '回款总额大于合同总额，请减少回款金额！',// 确认文本
        //        clickButton: function (sender, modal, index) {// 按钮事件处理
        //            $(this).closeDialog(modal);
        //        }
        //    });
        //    return;
        //}

    });
    function savepay(paidSum){
        var sReceivedPaymentTotalId = jQuery('#sReceivedPaymentTotalId').val();
        var nReceivedPaymentActualPrice = jQuery('#nReceivedPaymentActualPrice').val();
        var sReceivedPaymentPersonId = jQuery('#sReceivedPaymentPersonId').val();
        var sReceivedPaymentTradeWay = jQuery('#sReceivedPaymentTradeWay').val();
        var dReceivedPaymentPlanAccDate = jQuery('#dReceivedPaymentPlanAccDate').val();
        var dReceivedPaymentActualAccDate = jQuery('#dReceivedPaymentActualAccDate').val();
        var payMan=jQuery('#sReceivedPaymentPersonId').find("option:selected").text();
        var sReceivedPaymentMemo = jQuery('#sReceivedPaymentMemo').val();
        var contractId = jQuery('#contractId').val();
        var contractType = jQuery('#contractType').val();
        var url = window.rootPath + '/ui/payment/isInitial/'+contractId+'/'+contractType;
        jQuery.ajax({
            type: 'get',
            url: encodeURI(url),
            dataType: 'json',
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                if (data.code == 0) {
                    $.springLemonDialog({
                        content: '请先初始化收账计划',// 确认文本
                        clickButton: function (sender, modal, index) {// 按钮事件处理
                            $(this).closeDialog(modal);
                        }
                    });
                    return;
                }
                else{
                    var url = window.rootPath + "/ui/payment/savePay?name=" + payMan;
                    var d = {
                        "sCreateUserId":$("#userId").val(),
                        "nReceivedPaymentDetailPrice": nReceivedPaymentActualPrice,
                        "sReceivedPaymentTradeWay": {"id":sReceivedPaymentTradeWay},
                        "dReceivedPaymentPlanAccDate": dReceivedPaymentPlanAccDate,
                        "sReceivedPaymentMemo": sReceivedPaymentMemo,
                        "sContractId": contractId,
                        "sContractType": contractType,
                        "sReceivedPaymentPersonId": sReceivedPaymentPersonId,
                        "sReceivedPaymentTotalId": {"id": sReceivedPaymentTotalId},
                        "dReceivedPaymentActualAccDate":dReceivedPaymentActualAccDate
                    };
                    jQuery(".savePayBtn").attr("disabled", true);
                    jQuery.ajax({
                        type: 'post',
                        url: encodeURI(url),
                        data: JSON.stringify(d),
                        dataType: 'json',
                        contentType: 'application/json;charset=utf-8',
                        success: function (data) {
                            jQuery('#id').val('');
                            jQuery('#sReceivedPaymentTotalId').val('');
                            jQuery('#sReceivedPaymentTotalId-identify').val('');
                            jQuery('#sReceivedPaymentTradeWay').val(sReceivedPaymentTradeWay);
                            var time=moment(new Date).format('YYYY-MM-DD');
                            jQuery('#dReceivedPaymentActualAccDate').val(time);
                            jQuery('#dReceivedPaymentPlanAccDate').val("");
                            jQuery('#sReceivedPaymentPersonId').val(sReceivedPaymentPersonId);
                            jQuery('#nReceivedPaymentDetailPrice').val('');
                            jQuery('#sReceivedPaymentMemo').val('');
                            jQuery('#nReceivedPaymentActualPrice').val('');
                            jQuery('#sReceivedPaymentTradeWay').val('');
                            serverTable1.draw(true);
                            serverTable3.draw(true);
                            jQuery(".savePayBtn").attr("disabled", false);
                            if(data.code==1){
                                jQuery('#paySum').val(data.sum);
                                jQuery('#paidRemain').val(contractSum-data.sum);
                            }
                        }
                    });
                }
            }
        });
    };
    ///编辑保存回款
    jQuery('.savePayBtn1').on('click', function () {
        if (jQuery("#registPayEditForm") && !jQuery("#registPayEditForm").Validform({
                tiptype : 3,
                showAllError : true
            }).check(false)) {
            return;
        };
        var id = jQuery('#id').val();
        var sReceivedPaymentTotalId = jQuery('#sReceivedPaymentTotalId1').val();
        var nReceivedPaymentActualPrice = jQuery('#nReceivedPaymentActualPrice1').val();
        var sReceivedPaymentPersonId = jQuery('#sReceivedPaymentPersonId1').val();
        var sReceivedPaymentTradeWay = jQuery('#sReceivedPaymentTradeWay1').val();
        var dReceivedPaymentPlanAccDate = jQuery('#dReceivedPaymentPlanAccDate1').val();
        var dReceivedPaymentActualAccDate = jQuery('#dReceivedPaymentActualAccDate1').val();
        var payMan=jQuery('#sReceivedPaymentPersonId1').find("option:selected").text();
        var sReceivedPaymentMemo = jQuery('#sReceivedPaymentMemo1').val();
        var contractId = jQuery('#contractId').val();
        var contractType = jQuery('#contractType').val();
        var paid=jQuery('#paySum').val();
        var remainSum=sumScheduleSum-paid;
        if(parseFloat(oldReceivednBeLeftOverPrice) < parseFloat(nReceivedPaymentActualPrice)){
        	$.springLemonDialog({
                content: '输入金额大于开票剩余金额，请重新输入！',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
            return;
        }
        //if(parseInt(paidSum-oldpay)<=parseInt(paySum)) {
            if (parseInt(nReceivedPaymentActualPrice-oldpay, 10) <= parseInt(remainSum, 10)) {
                var url = window.rootPath + "/ui/payment/upDataPay?name=" + payMan;
                var d = {
                    "id": id,
                    "sCreateUserId":$("#userId").val(),
                    "nReceivedPaymentDetailPrice": nReceivedPaymentActualPrice,
                    "sReceivedPaymentTradeWay": {"id":sReceivedPaymentTradeWay},
                    "dReceivedPaymentPlanAccDate": dReceivedPaymentPlanAccDate,
                    "sReceivedPaymentMemo": sReceivedPaymentMemo,
                    "sContractId": contractId,
                    "sContractType": contractType,
                    "sReceivedPaymentPersonId": sReceivedPaymentPersonId,
                    "sReceivedPaymentTotalId": {"id": sReceivedPaymentTotalId},
                    "dReceivedPaymentActualAccDate":dReceivedPaymentActualAccDate
                };
                jQuery(".savePayBtn1").attr("disabled", true);
                jQuery.ajax({
                    type: 'post',
                    url: encodeURI(url),
                    data: JSON.stringify(d),
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    success: function (data) {
                        jQuery('#registPayEditModal').modal('hide');
                        serverTable1.draw(false);
                        serverTable3.draw(true);
                        jQuery(".savePayBtn1").attr("disabled", false);
                        if (data.code == 1) {
                            jQuery('#paySum').val(data.sum);
                            jQuery('#paidRemain').val(contractSum - data.sum);
                        }
                    }
                });
            }
            else{
                $.springLemonDialog({
                    content: '回款总额大于计划总额，请减少回款金额！',// 确认文本
                    clickButton: function (sender, modal, index) {// 按钮事件处理
                        $(this).closeDialog(modal);
                    }
                });
                return;
            }
        //}
        //else{
        //    $.springLemonDialog({
        //        content: '回款总额大于合同总额，请减少回款金额！',// 确认文本
        //        clickButton: function (sender, modal, index) {// 按钮事件处理
        //            $(this).closeDialog(modal);
        //        }
        //    });
        //    return;
        //}
        });
    //删除回款
    jQuery('.deletePayBtn').on('click', function () {
        var selects = getSelect("#payTable", 1);
        var url = window.rootPath + "/ui/payment/deletePay";
        if(selects.length==0){
            $.springLemonDialog({
                content: '请选择删除的记录',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
        }else{
            var ids=selects[0].id;
            for(var i=1;i<selects.length;i++){
                ids += ',' + selects[i].id;
            }
            var api=url+"?ids="+ids;
            $.springLemonDialog({
                content: '确认删除'+selects.length+'条记录？',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    if (index == 0) {
                        jQuery(".btn").attr("disabled", true);
                        jQuery.ajax({
                            url:encodeURI(api),
                            cache:false,
                            type :"get",
                            dataType:"json",
                            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
                            success:function(data){
                                jQuery(".btn").attr("disabled", false);
                                serverTable1.draw(false);
                                serverTable3.draw(false);
                                if(data.code==1){
                                    jQuery('#paySum').val(data.sum);
                                    jQuery('#paidRemain').val(contractSum-data.sum);
                                }
                            }
                        });
                    }
                    $(this).closeDialog(modal);
                }
            });
        }
    });
//获取开票历史tabs页面数据 服务器分页
    var serverData2 = {};
    var	serverTable2;
    jQuery(document).ready(function () {
        serverTable2 = jQuery('#paymentTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url": window.rootPath + '/ui/payment/paymentHistory/'+contractId+'/'+contractType+'/getData',
                "data": function (d) {
                    return $.extend({}, d, serverData2);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: null,
                    defaultContent: "",
                    render: function (data, type, full, meta) {
                        var operate = '<input type="checkbox" class="checkchild">';
                        return operate;

                    }
                },
                {
                    data: 'nInvoiceDetailPrice'
                },
                {
                    data:'dInvoiceActualAccDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY-MM-DD');
                        else
                            return '';
                    }
                },
                {
                    data: 'sInvoicePersonName'
                },
                {
                    data:'sInvoiceMemo'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
    
    jQuery('#clearsInvoiceTotalId1').on( 'click', function() {
    	jQuery('#sInvoiceTotalId1').val("");
    	jQuery('#sInvoiceTotalname1').val("");
    });
    jQuery('#getsInvoiceTotalId1').on( 'click', function() {
    	jQuery('#search2').val("");
    	InvoiceTotalTablelength(jQuery('#search2').val(),'invoiceTotalTable1');
		jQuery("#InvoiceTotalIdModel1").modal('show');
	});
    
    jQuery('#btn-search2').on( 'click', function() {
    	InvoiceTotalTablelength(jQuery('#search2').val(),'invoiceTotalTable1');
	});
    
    jQuery('#btn-reset2').on( 'click', function() {
    	jQuery('#search2').val("");
    	InvoiceTotalTablelength(jQuery('#search2').val(),'invoiceTotalTable1');
	});
    
    jQuery('.getLaction1').on('click', function(){
    	var selects=getSelectR("#invoiceTotalTable1",1);
		if(selects.length>1){
   		   message("只能引入一条开票信息！");
   	    }
   	    else if(selects.length==0){
   		    message("没有选中开票信息！");
   	    }else if(selects.length==1){
   	    	jQuery("#sInvoiceTotalId1").val(selects[0].id);
   	    	jQuery("#sInvoiceTotalname1").val(selects[0].sInvoiceName);
		   	jQuery("#paymentSum1").val(selects[0].nBeLeftOverPrice);
		   	oldnBeLeftOverPrice = selects[0].nBeLeftOverPrice;
		   	jQuery("#paymentDate1").val(selects[0].dInvoiceDate.substring(0,10));
		   	jQuery("#paymentMan1").val(selects[0].sInvoicePeopleId);
		   	jQuery("#paymentMan1").select2().trigger("change");
   	    	jQuery("#InvoiceTotalIdModel1").modal('hide');
   	    }
    });
    
    //编辑开票历史
    jQuery('.editPaymentBtn').on('click', function () {
        var selects=getSelect("#paymentTable",1);
        if(selects.length>1){
            $.springLemonDialog({
                content: '只能编辑一条记录',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
        }
        else if(selects.length==0){
            $.springLemonDialog({
                content: '请选择要编辑的记录',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
        }else if(selects.length==1) {
            jQuery('#id1').val(selects[0].id);
            var sInvoiceTotalId = jQuery('#sInvoiceTotalId').val();
            if(sInvoiceTotalId != "" && sInvoiceTotalId != undefined){
            	jQuery('#sInvoiceTotalId1').val(selects[0].sInvoiceTotalId.id);
            	jQuery('#sInvoiceTotalname1').val(selects[0].sInvoiceTotalId.sInvoiceName);
            }
            jQuery('#paymentSum1').val(selects[0].nInvoiceDetailPrice);
            oldpayment=jQuery('#paymentSum1').val();
            jQuery('#paymentMan1').val(selects[0].sInvoicePersonId);
            jQuery("#paymentMan1").select2().trigger("change");
            if(selects[0].dInvoiceActualAccDate){
                var time=moment(selects[0].dInvoiceActualAccDate).format('YYYY-MM-DD');
                jQuery('#paymentDate1').val(time);
            }
            jQuery('#memo2').val(selects[0].sInvoiceMemo);
            remain=jQuery('#remain').val();//剩余开票金额
            jQuery('#registPaymentEditModal').modal('show');
        }
    });
    ///编辑保存开票
    jQuery('.savePaymentBtn1').on('click', function () {
        if (jQuery("#registPaymentEditForm") && !jQuery("#registPaymentEditForm").Validform({
                tiptype : 3,
                showAllError : true
            }).check(false)) {
            return;
        };
        var paymentSum = jQuery('#paymentSum1').val();
        var paid=jQuery('#payment').val();
        var remainSum=sumScheduleSum-paid;
        if(parseFloat(oldnBeLeftOverPrice) < parseFloat(paymentSum)){
        	$.springLemonDialog({
                content: '输入金额大于开票剩余金额，请重新输入！',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
            return;
        }
       // if(parseInt(paymentSum-oldpayment)<=parseInt(remain)) {
            if (parseInt(paymentSum - oldpayment) <= parseInt(remainSum)) {
                saveEditpayment(paymentSum);
            }
            else{
                $.springLemonDialog({
                    content: '开票总额大于计划总额，请减少开票金额！',// 确认文本
                    //otherButtons : [ "继续", "取消" ],
                    clickButton: function (sender, modal, index) {// 按钮事件处理
                        $(this).closeDialog(modal);
                    }
                });
                return;
            }
        //}
        //else{
        //    $.springLemonDialog({
        //        content: '开票总额大于合同总额，请减少回款金额！',// 确认文本
        //        otherButtons : [ "继续", "取消" ],
        //        clickButton: function (sender, modal, index) {// 按钮事件处理
        //            if(index==0){
        //                saveEditpayment(paymentSum);
        //            }
        //            $(this).closeDialog(modal);
        //        }
        //    });
        //    return;
        //}
        });
    function saveEditpayment(paymentSum){
        var id = jQuery('#id1').val();
        var paymentMan = jQuery('#paymentMan1').find("option:selected").text();
        var paymentManID=jQuery('#paymentMan1').val();
        var paymentDate=jQuery('#paymentDate1').val();
        var memo = jQuery('#memo2').val();
        var contractId=jQuery('#contractId').val();
        var contractType=jQuery('#contractType').val();
        var sInvoiceTotalId = jQuery('#sInvoiceTotalId1').val();
        var url = window.rootPath + "/ui/payment/upDataPayment?name=" + paymentMan;
        var d = {
                    "id": id,
                    "sInvoiceTotalId": {"id":sInvoiceTotalId},
                    "nInvoiceDetailPrice": paymentSum,
                    "sInvoicePersonId":paymentManID,
                    "dInvoiceActualAccDate": paymentDate,
                    "sInvoiceMemo": memo,
                    "sContractId": contractId,
                    "sContractType": contractType
                };
        jQuery(".savePaymentBtn1").attr("disabled", true);
        jQuery.ajax({
                    type: 'post',
                    url: encodeURI(url),
                    data: JSON.stringify(d),
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    success: function (data) {
                        jQuery('#registPaymentEditModal').modal('hide');
                        serverTable2.draw(true);
                        serverTable4.draw(true);
                        jQuery(".savePaymentBtn1").attr("disabled", false);
                        if (data.code == 1) {
                            jQuery('#payment').val(data.sum);
                            jQuery('#remain').val(contractSum - data.sum);
                        }
                    }
                });
    };
    ///新增保存开票
    jQuery('.savePaymentBtn').on('click', function () {
        if(jQuery("#paymentRegist")&&!jQuery("#paymentRegist").Validform({
                tiptype :3,
                showAllError :true
            }).check(false)){
            return;
        };
        remain=jQuery('#remain').val();//剩余开票金额
        var paymentSum = jQuery('#paymentSum').val();
        var paid=jQuery('#payment').val();
        var remainSum=sumScheduleSum-paid;
        if(parseFloat(oldnBeLeftOverPrice) < parseFloat(paymentSum)){
        	$.springLemonDialog({
                content: '输入金额大于开票剩余金额，请重新输入！',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
            return;
        }
       // if(parseInt(paymentSum)<=parseInt(remain)) {
            if (parseInt(paymentSum, 10) <= parseInt(remainSum, 10)) {
                savepayment(paymentSum);
            }
            else{
                $.springLemonDialog({
                    content: '开票总额大于计划总额，请减少开票金额！',// 确认文本
                  //  otherButtons : [ "继续", "取消" ],
                    clickButton: function (sender, modal, index) {// 按钮事件处理
                        $(this).closeDialog(modal);
                    }
                });
                return;
            }
        //}
        //else{
        //    $.springLemonDialog({
        //        content: '开票总额大于合同总额，请减少开票金额！',// 确认文本
        //        otherButtons : [ "继续", "取消" ],
        //        clickButton: function (sender, modal, index) {// 按钮事件处理
        //            if(index==0){
        //                savepayment(paymentSum);
        //            }
        //            $(this).closeDialog(modal);
        //        }
        //    });
        //    return;
        //}
    });
    function savepayment(paymentSum){
        var paymentMan = jQuery('#paymentMan').find("option:selected").text();
        var paymentManID=jQuery('#paymentMan').val();
        var paymentDate = jQuery('#paymentDate').val();
        var memo = jQuery('#memo').val();
   //     var taxRate = jQuery('#taxRate').val();
        var isInIncome = jQuery('#isInIncome').val();
   //     var taxes = jQuery('#taxes').val();
        var contractId = jQuery('#contractId').val();
        var contractType = jQuery('#contractType').val();
        var sInvoiceTotalId = jQuery('#sInvoiceTotalId').val();
        var url = window.rootPath + '/ui/payment/isInitial/'+contractId+'/'+contractType;
        jQuery.ajax({
            type: 'get',
            url: encodeURI(url),
            dataType: 'json',
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                if (data.code == 0) {
                    $.springLemonDialog({
                        content: '请先初始化收账计划',// 确认文本
                        clickButton: function (sender, modal, index) {// 按钮事件处理
                            $(this).closeDialog(modal);
                        }
                    });
                    return;
                }
                else{
                    var url = window.rootPath + "/ui/payment/savePayment?name=" + paymentMan;
                    var d = {
                        "sCreateUserId":$("#userId").val(),
                        "sInvoiceTotalId": {"id":sInvoiceTotalId},
                        "nInvoiceDetailPrice": paymentSum,
                        "sInvoicePersonId":paymentManID,
                        "dInvoiceActualAccDate": paymentDate,
                        "sInvoiceMemo": memo,
                     //   "nInvoiceTaxRate":taxRate,
                        //"isInIncome":isInIncome,
                   //     "nInvoiceTaxPrice":taxes,
                        "sContractId": contractId,
                        "sContractType": contractType
                    };
                    jQuery(".savePaymentBtn").attr("disabled", true);
                    jQuery.ajax({
                        type: 'post',
                        url: encodeURI(url),
                        data: JSON.stringify(d),
                        dataType: 'json',
                        contentType: 'application/json;charset=utf-8',
                        success: function (data) {
                            jQuery('#id').val("");
                            jQuery('#sInvoiceTotalId').val("");
                            jQuery('#sInvoiceTotalname').val("");
                            jQuery('#paymentSum').val("");
                            jQuery('#paymentMan').val(paymentMan);
                            var time=moment(new Date).format('YYYY-MM-DD');
                            jQuery('#paymentDate').val(time);
                       //     jQuery('#taxes').val("0");
                            jQuery('#isInIncome').val("是");
                       //     taxRate = jQuery('#taxRate').val(17);
                            jQuery('#memo').val("");
                            jQuery('#createTime').val("");
                            serverTable2.draw(true);
                            serverTable4.draw(true);
                            jQuery(".savePaymentBtn").attr("disabled", false);
                            if(data.code==1){
                                jQuery('#payment').val(data.sum);
                                jQuery('#remain').val(contractSum-data.sum);
                            }
                        }
                    });
                }
            }
        });
    };
    //删除开票
    jQuery('.deletePaymentBtn').on('click', function () {
        var selects = getSelect("#paymentTable", 1);
        var url = window.rootPath + "/ui/payment/deletePayment";
        if(selects.length==0){
            $.springLemonDialog({
                content: '请选择删除的记录',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
        }else{
            var ids=selects[0].id;
            for(var i=1;i<selects.length;i++){
                ids += ',' + selects[i].id;
            }
            var api=url+"?ids="+ids;
            $.springLemonDialog({
                content: '确认删除'+selects.length+'条记录？',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    if (index == 0) {
                        jQuery(".btn").attr("disabled", true);
                        jQuery.ajax({
                            url:encodeURI(api),
                            cache:false,
                            type :"get",
                            dataType:"json",
                            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
                            success:function(data){
                                jQuery(".btn").attr("disabled", false);
                                serverTable2.draw(false);
                                serverTable4.draw(false);
                                if(data.code==1){
                                    jQuery('#payment').val(data.sum);
                                    jQuery('#remain').val(contractSum-data.sum);
                                }
                            }
                        });
                    }
                    $(this).closeDialog(modal);
                }
            });
        }
    });
//获取回款-计划tabs页面数据 服务器分页
    var serverData3 = {};
    var	serverTable3;
    jQuery(document).ready(function () {
        serverTable3 = jQuery('#paidScheduleTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url": window.rootPath + '/ui/payment/payPlan/'+contractId+'/'+contractType+'/getData',
                "data": function (d) {
                    return $.extend({}, d, serverData3);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: 'fund'
                },
                {
                    data: 'scheduleSum'
                },
                {
                    data:'paidStage'
                },
                {
                    data:'schedulePayDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data:'deviationDate'
                },
                {
                    data:'memo'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
//获取开票-计划tabs页面数据 服务器分页
    var serverData4 = {};
    var	serverTable4;
    jQuery(document).ready(function () {
        serverTable4 = jQuery('#paymentScheduleTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url": window.rootPath + '/ui/payment/paymentPlan/'+contractId+'/'+contractType+'/getData',
                "data": function (d) {
                    return $.extend({}, d, serverData4);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: 'fund'
                },
                {
                    data:'paymentStage'
                },
                {
                    data:'schedulePayDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data:'memo'
                }
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
})();